//引入redux模块
import { createStore } from "redux"
//初始值
const defaultState = {
    msg: "redux的数据",
    toastData: {
        isshow: false,
        message: "登录成功",
        type: "success"
    }
}
//ts函数必须要指定类型

interface IToast {
    message: string,
    type: 'success' | 'info' | 'warning' | 'error'
}

const reducer = (state: IState = defaultState, action: IAction) => {
    let nstate = JSON.parse(JSON.stringify(state))
    switch (action.type) {
        case "showToast":
            let value = action.value as IToast
            nstate.toastData.isshow = true
            nstate.toastData.message = value.message
            nstate.toastData.type = value.type
            break;
        case "hideTosast":
            nstate.toastData.isshow = false
            break;
    }
    return nstate
}
//创建仓库
const store = createStore(reducer)
//开放出去
export default store